<!--
* description: 备件借用查询_网点&总部
* author: xuliwen
* createdDate: 2021-3-1
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-api-style="'restful'"
      :callback-obj="callbackObj"
    />

  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import Vue from "vue";
import api from '@/api/pa/apiBranchWarehouse'
import { exportExcel } from '@/utils/getTimeString.js'

export default {
  name: "",

  components: {
    OneTableTemplate,
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ""], function () {
      next();
    });
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);

    return {
      icon: "el-icon-arrow-down",
      status: false,
      editRowData: {},
      selectiondata: null,
      // 网格查询API配置对象
      apiConfig:api.borrowingPartQuery,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          name: "search",
          clickEvent: () => this.queryTable(1),
          text: this.$t("sys.button.query"), // 查询
          position: "right",
          fuzzySearch: true,
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          name: "reset",
          clickEvent: () => this.reset(),
          text: this.$t("sys.button.reset"),
          position: "right", // 重置
        },
       {
          compKey: "btnKey3",
          type: "",
          size: "small",
          clickEvent: () => this.exportExcel111(),
          text: "导出",
          name: "export",
          position: "left",
        },
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
             {
                compKey: "compKey1",
                labelName: "网点编码：",
                codeField: "dlrCode",
                component: () => import("@/components/ve/multipleSearchInput"),
                type: "inputText",
                isMust: true,
                dataToObject: {
                  // 控制弹窗页面 搜索 网格 元素
                  tableComponents: [
                    {
                      compKey: "compKey1",
                      labelName: "门店编码：",
                      codeField: "dlrCode",
                      component: () => import("@/components/org/commonInput"),
                      type: "inputText",
                      isMust: true,
                      span: 8,
                    },
                    {
                      compKey: "compKey2",
                      labelName: "门店名称：",
                      codeField: "dlrShortName",
                      component: () => import("@/components/org/commonInput"),
                      type: "inputText",
                      isMust: true,
                      span: 8,
                    },
                  ],
                  tableCols: [
                    {
                      prop: "dlrCode",
                      label: "门店编码",
                    },
                    {
                      prop: "dlrShortName",
                      label: "门店名称",
                    },
                  ],
                  returnField: {
                    prop: "dlrShortName",
                    label: "门店名称",
                  },
                  // api: orgApis.vehicleQuery
                },
                span: 6,
              },
              {
                compKey: "compKey2",
                labelName: "网点名称：",
                codeField: "dlrShortName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey3",
                labelName: "借件单号：",
                codeField: "borrowCode",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey4",
                labelName: "仓库名称: ",
                codeField: "warehouseName",
                textField: "warehouseName",
                customObj: {
                  api: api.queryWareHouse,
                  defOptionFields:['warehouseId','warehouseName']
                },
                component: () => import('@/components/org/commonSelect'),
                type: 'dropdownList',
                isMul: false,
                isMust: true,
              },
               {
                compKey: "compKey5",
                labelName: "借件人员：",
                codeField: "applierId",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: false,
              },
              {
                 compKey: 'compKey6',
                labelName: '借件日期：',
                codeField: 'applyDateStart,applyDateEnd',
                component: () => import('@/components/org/datePicker/andtDatePicker'),
                type:'YYYY-MM-DD HH:mm:ss',
            // type: 'twoDatePicker',
            //     dataToObject:{timer:true,thirtyTime:true},
                // hhmmss: true,    //默认有时分秒
                format: 'yyyy-MM-dd',
                isMul: false,
                isMust: false,
              },
              {
                 compKey: 'compKey7',
                labelName: '承诺归还日期：',
                codeField: 'promisesRuturnDateStart,promisesRuturnDateEnd',
                component: () => import('@/components/org/datePicker/andtDatePicker'),
                type:'YYYY-MM-DD HH:mm:ss',
            // type: 'twoDatePicker',
            //     dataToObject:{timer:true,thirtyTime:true},
                // hhmmss: true,    //默认有时分秒
                format: 'yyyy-MM-dd',
                isMul: false,
                isMust: false,
              },
               {
                compKey: "compKey8",
                labelName: "VIN：",
                codeField: "vin",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: false,
              },
            ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "dlrId",
                label: "网点ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "warehouseId",
                label: "仓库ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "partId",
                label: "备件ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "updateControlId",
                label: "并发字段",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "borrowCode",
                label: "借件单号",

              },
              {
                prop: "warehouseName",
                label: "仓库名称",
              },
              {
                prop: "applierId",
                label: "借件人员",
              },

              {
                prop: "linkPhone",
                label: "联系电话",
              },
              {
                prop: "applyDate",
                label: "借件日期",
              },
              {
                prop: "vin",
                label: "VIN",
              },
                {
                prop: "partNo",
                label: "备件编号",
              },
                {
                prop: "partName",
                label: "备件名称",
              },
              {
                prop: "borrowQty",
                label: "借件数量",
              },
              {
                prop: "returnQty",
                label: "归还数量",
              },
              {
                prop: "promisesRuturnDate",
                label: "承诺归还日期",
              },
              {
                prop: "allReturnDate",
                label: "全部归还日期",
              },
                {
                prop: "unableReturnQty",
                label: "无法归还数",
              },
                {
                prop: "remark",
                label: "无法归还原因",
              },
                {
                prop: "",
                label: "备件类别",
              },
                {
                prop: "carConfigIdList",
                label: "适用车型",
              },
                {
                prop: "",
                label: "备件属性",
              },
                {
                prop: "",
                label: "SNP",
              },
                 {
                prop: "pointPriceTax",
                label: "借件单价",
              },
              {
                prop: "aebitAmount",
                label: "借件金额",
              },
            ],
      callbackObj: {
        // 手动勾选时
        onCheckSelect: (selection, row) => {
          this.selectiondata = selection;
        },
        onCheckSelectChange: (selection) => {
          this.onCheckSelectChange1(selection);
        },
      },
      // 表单查询数据
      formField: this.$utils.getFormField(
        this,
        {
          applyDateStart:'',
          applyDateEnd:'',
          dlrCode: "",
          dlrShortName: "",
          borrowCode: "",
          warehouseName: "",
          applierId: "",
          vin: "",
          promisesRuturnDateStart:'',
          promisesRuturnDateEnd:'',
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
    };
  },
  watch: {
    "formField.orderStatus": {
      deep: true,
      handler: function (newV, oldV) {
        console.log("watch中：", newV);
        // this.querybystatus(newV)
        this.queryTable();
      },
    },
  },
  mounted() {
    // 列表查询
    this.queryTable(1)
  },

  methods: {
              //导出
   exportExcel111(){
      //导出
       exportExcel(this.formField, api.borrowingPartQueryExportDetails.APIUrl, api.borrowingPartQueryExportDetails.ServiceCode, '备件借用查询_网点&总部')

    },
  },
};
</script>
<style lang='scss' scoped>
.red {
  background: red;
}
</style>
